#include	<stdio.h>
#include	<string.h>
#include	<algorithm>

const int nmax = 200;

int keyTable[nmax];
char msg[nmax+4];
char enmsg[nmax+4];
int  cycle[nmax];
int  overallCycle;
int  intermediaValue[nmax][nmax+4];

int gcd(int a, int b) 
{
    int x = a, r = b;
    if (a < b) { x = b; r = a; }
    while (x % r) {
       int temp = r;
       r = x % r;
       x = temp;
    }
    return r;
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

void preTreatMent(int n)
{
    for (int i = 0; i < n; ++i) {
        intermediaValue[i][0] = i;
        int jj = 1, pos = i;
        for (jj = 1; jj <= n; ++jj)
        {
            pos = keyTable[pos];
            intermediaValue[i][jj] = pos;
            if (pos == i)
                break;
        }
        cycle[i] = jj;
    }
    overallCycle = 1;
    for (int i = 0; i < n; ++i)
        overallCycle = lcm(overallCycle, cycle[i]);
}
void getEncodedMsg(char *dst, const char *msg, int K, int n)
{
    //int mod = K % overallCycle;
    for (int i = 0; i < n; ++i)
        dst[intermediaValue[i][K%cycle[i]]] = msg[i]; 
}

int main(int argc, char *argv[])
{
    int n, K;
    while (scanf("%d", &n) == 1 && n) {
        for (int i = 0; i < n; ++i) {
            scanf("%d", &keyTable[i]);
            --keyTable[i];
        }
        while (scanf("%d", &K) == 1 && K) {
            getchar();
            fgets(msg, sizeof(msg), stdin);
            int len = strlen(msg);
            if (msg[len-1] == '\n') {
                --len;
                msg[len] = '\0';
            }
            for (int j = len; j < n; ++j)
                msg[j] = ' ';
            msg[n] = '\0';
            memset(enmsg, 0x00, sizeof(enmsg));
            preTreatMent(n);
            getEncodedMsg(enmsg, msg, K, n);
            printf ( "%s\n", enmsg);
        }
    }
    return 0;
}
